<?php
class ConfigAction extends Action {
	public function index(){
		if(isset($_SESSION['uid'])){
			$con_arr=require('config.php');
			$this->assign('config',$con_arr);
			$this->assign('title','后台配置');
			$this->display();
		}else{
			$this->redirect('Index/login');
		}
	}

	public function update(){
		if($this->isPost()){
			$update=array_filter($_POST);
			$con_arr=require('config.php');
			$keys=array_map('strtoupper',array_keys($update));
			$update=array_combine($keys,$update);
			$con_arr=array_merge($con_arr,$update);
			
			#dump($con_arr);
			$str='<?php return array(';
			foreach($con_arr as $key=>$val){
				$str.='\''.$key.'\'=>\''.$val.'\',';
			}
			$str=rtrim($str,',');
			$str.=' );';
			#dump($str);
			$file='config.php';
			if(file_put_contents($file,$str)){
				$this->success('修改成功');
			}else{
				$this->error('修改失败');
			}
			
		}
	}
}
?>